////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//   Software       :                                                         //
//   Layer          : SRC                                                     //
//   Package        :                                                         //
//   Component      :                                                         //
//                                                                            //
//   File           : FormConfig.cxx                                          //
//   Author         : RSO ( Rafael Sotomayor Brûlé )                          //
//   EMail          : rsotomayor@savtec.cl                                    //
//   Type           : C++ Source                                              //
//   Usage          :                                                         //
//   Purpose        : Definición de ATD  globales                             //
//                                                                            //
//                                                                            //
//   who when        what                                                     //
//   ~~~ ~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
//   RSO 09-10-2010  Creation                                                 //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////

#include "mylib/errlog.h"
#include "mylib/utilconf.h"

#include "xsendkey.h"
#include "formconfig.h"
#include "formmain.h"

#include "myglobal.h"
#include "myconfig.h"
#include "cdatabase.h"


extern FormMain    *myFormMain_g;

extern MyGlobal   *global_g;
extern MyConfig  *config_g;

extern GtkBuilder   *builder_g;
extern CDataBase   *database_g;

FormConfig* FormConfig::pFormConfig_a=NULL;


FormConfig::FormConfig() {
  pFormConfig_a = this ;
  ptimer_a=0;
  flagInit_a = false ;

  
  keyup_a = 0 ;
  myWidget_a = g_slice_new( MyWidget );
  MyForm::init();
}
FormConfig::~FormConfig() {
  g_slice_free( MyWidget, myWidget_a );	
}

gint FormConfig::RePaint(gpointer data) {


  return FALSE;
}

int FormConfig::initialize(string fileGlade_p) {

  if ( fileGlade_p != "" ) {
    builder_g = gtk_builder_new ();
    gtk_builder_add_from_file (builder_g, fileGlade_p.data(), NULL);
  } 
  
  window_a = GTK_WIDGET (gtk_builder_get_object (builder_g, "windowconfig"));
  gtk_builder_connect_signals (builder_g, NULL);  


  //~ PangoFontDescription    *fd = NULL;
  //~ fd = pango_font_description_from_string ("Courier Bold 22");

#if defined(__arm__)  
  gtk_window_set_decorated((GtkWindow* ) window_a, FALSE);  
#endif

  myWidget_a->notebookconfig             =  GTK_WIDGET (gtk_builder_get_object (builder_g,"notebookconfig")); 

  myWidget_a->buttonconfiguracioncerrar    =  GTK_WIDGET (gtk_builder_get_object (builder_g,"buttonconfiguracioncerrar"));  


  myWidget_a->entryServerHostName        =  GTK_WIDGET (gtk_builder_get_object (builder_g,"entryServerHostName")); 
  myWidget_a->entryServerAddress         =  GTK_WIDGET (gtk_builder_get_object (builder_g,"entryServerAddress")); 
  myWidget_a->entryServerUrl             =  GTK_WIDGET (gtk_builder_get_object (builder_g,"entryServerUrl"));
  myWidget_a->entryServerPort            =  GTK_WIDGET (gtk_builder_get_object (builder_g,"entryServerPort"));

  myWidget_a->entryServicioAddress       =  GTK_WIDGET (gtk_builder_get_object (builder_g,"entryServicioAddress")); 
  myWidget_a->entryServicioPort          =  GTK_WIDGET (gtk_builder_get_object (builder_g,"entryServicioPort")); 
  myWidget_a->entryServicioRfIdPort      =  GTK_WIDGET (gtk_builder_get_object (builder_g,"entryServicioRfIdPort")); 

  myWidget_a->entryWlanSSID              =  GTK_WIDGET (gtk_builder_get_object (builder_g,"entryWlanSSID")); 
  myWidget_a->entryWlanWpaKey            =  GTK_WIDGET (gtk_builder_get_object (builder_g,"entryWlanWpaKey")); 
  myWidget_a->comboboxProveedorMovil     =  GTK_WIDGET (gtk_builder_get_object (builder_g,"comboboxProveedorMovil")); 

  myWidget_a->checkbuttonEthDhcp         =  GTK_WIDGET (gtk_builder_get_object (builder_g,"checkbuttonEthDhcp")); 
  myWidget_a->entryEthAddress            =  GTK_WIDGET (gtk_builder_get_object (builder_g,"entryEthAddress")); 
  myWidget_a->entryEthMask               =  GTK_WIDGET (gtk_builder_get_object (builder_g,"entryEthMask")); 
  myWidget_a->entryEthGateway            =  GTK_WIDGET (gtk_builder_get_object (builder_g,"entryEthGateway")); 
  myWidget_a->entryDNS                   =  GTK_WIDGET (gtk_builder_get_object (builder_g,"entryDNS")); 

  myWidget_a->buttongrabarconfiguracion  =  GTK_WIDGET (gtk_builder_get_object (builder_g,"buttongrabarconfiguracion")); 

  int i=0;
  char bufferTxt[32];
  for ( i=0;i < 10 ; i++ ) {
    sprintf(bufferTxt,"buttonenr%d",i);
    myWidget_a->keypadnum[i] =  GTK_WIDGET (gtk_builder_get_object (builder_g,bufferTxt));  
  }

  int index=0;
  for ( i='a';i < ('z' + 1) ; i++ ) {
    sprintf(bufferTxt,"buttonenr%c",i);
    myWidget_a->keypadletter[index++] =  GTK_WIDGET (gtk_builder_get_object (builder_g,bufferTxt));  
  }

  sprintf(bufferTxt,"buttonenregne");
  myWidget_a->keypadletter[index++] =  GTK_WIDGET (gtk_builder_get_object (builder_g,bufferTxt));  

  myWidget_a->keypadbarspace   = GTK_WIDGET (gtk_builder_get_object (builder_g,"buttonenrbarspace"));  
  myWidget_a->keypadbloqmayus  = GTK_WIDGET (gtk_builder_get_object (builder_g,"buttonenrblockmayus"));  
  myWidget_a->keypadbkspace    = GTK_WIDGET (gtk_builder_get_object (builder_g,"buttonenrbkspace"));  
  myWidget_a->keypadslash      = GTK_WIDGET (gtk_builder_get_object (builder_g,"buttonenrslash"));  

  myWidget_a->keypadcomma      = GTK_WIDGET (gtk_builder_get_object (builder_g,"buttonenrcoma"));  
  myWidget_a->keypadpunto      = GTK_WIDGET (gtk_builder_get_object (builder_g,"buttonenrpunto"));  
  myWidget_a->keypadraya       = GTK_WIDGET (gtk_builder_get_object (builder_g,"buttonenrraya"));  

  string filename ;
  filename  = config_g->pathImage_a ;
  filename += "s100_bg.png";   
  setBackGround(filename);

  setImageButton(GTK_BUTTON(myWidget_a->buttonconfiguracioncerrar),(char *) "/icons/gnome/32x32/actions/window-close.png");  
  setImageButton(GTK_BUTTON(myWidget_a->buttongrabarconfiguracion),(char *) "/icons/gnome/32x32/actions/document-save.png");  

  flagInit_a = true ;


  initTabConfig();

  return 0;
}

void FormConfig::initTabConfig() {
  char bufferTxt[128] ;

  gtk_entry_set_text (GTK_ENTRY(myWidget_a->entryServerHostName),config_g->serverHostName_a.data());
  gtk_entry_set_text (GTK_ENTRY(myWidget_a->entryServerAddress),config_g->serverAddress_a.data());
  gtk_entry_set_text (GTK_ENTRY(myWidget_a->entryServerUrl),config_g->serverUrl_a.data());

  sprintf(bufferTxt,"%d",config_g->serverPort_a);
  gtk_entry_set_text (GTK_ENTRY(myWidget_a->entryServerPort),bufferTxt);

  sprintf(bufferTxt,"%d",config_g->portSocket_a);
  gtk_entry_set_text (GTK_ENTRY(myWidget_a->entryServicioPort),bufferTxt);
  gtk_entry_set_text (GTK_ENTRY(myWidget_a->entryServicioAddress),config_g->addressSocket_a.data());
  gtk_entry_set_text (GTK_ENTRY(myWidget_a->entryServicioRfIdPort),config_g->rfiddevice_a.data());

  gtk_entry_set_text (GTK_ENTRY(myWidget_a->entryWlanSSID),config_g->wlanSSID_a.data());
  gtk_entry_set_text (GTK_ENTRY(myWidget_a->entryWlanWpaKey),config_g->wlanKey_a.data());

  gtk_entry_set_text (GTK_ENTRY(myWidget_a->entryEthAddress),config_g->ethIpAddress_a.data());
  gtk_entry_set_text (GTK_ENTRY(myWidget_a->entryEthMask),config_g->ethMask_a.data());
  gtk_entry_set_text (GTK_ENTRY(myWidget_a->entryEthGateway),config_g->ethGateway_a.data());
  gtk_entry_set_text (GTK_ENTRY(myWidget_a->entryDNS),config_g->dns_a.data());


  if ( config_g->ethDhcp_a == 1 ) {
    GTK_TOGGLE_BUTTON (myWidget_a->checkbuttonEthDhcp)->active = TRUE ;
    gtk_entry_set_editable(GTK_ENTRY(pFormConfig_a->myWidget_a->entryEthAddress), FALSE);
    gtk_entry_set_editable(GTK_ENTRY(pFormConfig_a->myWidget_a->entryEthMask), FALSE);
    gtk_entry_set_editable(GTK_ENTRY(pFormConfig_a->myWidget_a->entryEthGateway), FALSE);
  } else {
    GTK_TOGGLE_BUTTON (myWidget_a->checkbuttonEthDhcp)->active = FALSE ;
    gtk_entry_set_editable(GTK_ENTRY(pFormConfig_a->myWidget_a->entryEthAddress), TRUE);
    gtk_entry_set_editable(GTK_ENTRY(pFormConfig_a->myWidget_a->entryEthMask), TRUE);
    gtk_entry_set_editable(GTK_ENTRY(pFormConfig_a->myWidget_a->entryEthGateway), TRUE);
  }

  initComboboxPPP();

  if ( pFormConfig_a->setComboBoxSelectValue(GTK_COMBO_BOX (myWidget_a->comboboxProveedorMovil),config_g->wvDial_a.data() ) == FALSE ) {
    gtk_combo_box_set_active(GTK_COMBO_BOX (myWidget_a->comboboxProveedorMovil),-1);
  }


}
void FormConfig::setCallBack() {

  g_signal_connect(GTK_OBJECT (window_a), "destroy", GTK_SIGNAL_FUNC (on_window_destroy), NULL);     
  g_signal_connect(GTK_OBJECT (window_a), "show", GTK_SIGNAL_FUNC (on_window_show), NULL);     
  g_signal_connect(GTK_OBJECT (myWidget_a->buttonconfiguracioncerrar), "clicked", GTK_SIGNAL_FUNC (on_window_close), NULL);


  int index=0;
  int i ;
  for ( i='0';i <= '9' ; i++ ) {
    g_signal_connect(GTK_OBJECT (myWidget_a->keypadnum[index++]), "clicked", GTK_SIGNAL_FUNC (on_window_config_keypad), GINT_TO_POINTER(i));
  }
  
  index=0;
  
  for ( i='a';i < ('z' + 1) ; i++ ) {
    g_signal_connect(GTK_OBJECT (myWidget_a->keypadletter[index++]), "clicked", GTK_SIGNAL_FUNC (on_window_config_keypad), GINT_TO_POINTER(i));
  }
  i='n' ;
  g_signal_connect(GTK_OBJECT (myWidget_a->keypadletter[index++]), "clicked", GTK_SIGNAL_FUNC (on_window_config_keypad), GINT_TO_POINTER(i));

  i=0x20;
  g_signal_connect(GTK_OBJECT (myWidget_a->keypadbarspace), "clicked", GTK_SIGNAL_FUNC (on_window_config_keypad), GINT_TO_POINTER(i));

  i=0x08;
  g_signal_connect(GTK_OBJECT (myWidget_a->keypadbkspace), "clicked", GTK_SIGNAL_FUNC (on_window_config_keypad), GINT_TO_POINTER(i));

  i=0x0E;
  g_signal_connect(GTK_OBJECT (myWidget_a->keypadbloqmayus), "clicked", GTK_SIGNAL_FUNC (on_window_config_keypad), GINT_TO_POINTER(i));

  i='/';
  g_signal_connect(GTK_OBJECT (myWidget_a->keypadslash), "clicked", GTK_SIGNAL_FUNC (on_window_config_keypad), GINT_TO_POINTER(i));

  i=',';
  g_signal_connect(GTK_OBJECT (myWidget_a->keypadcomma), "clicked", GTK_SIGNAL_FUNC (on_window_config_keypad), GINT_TO_POINTER(i));

  i='.';
  g_signal_connect(GTK_OBJECT (myWidget_a->keypadpunto), "clicked", GTK_SIGNAL_FUNC (on_window_config_keypad), GINT_TO_POINTER(i));

  i='-';
  g_signal_connect(GTK_OBJECT (myWidget_a->keypadraya), "clicked", GTK_SIGNAL_FUNC (on_window_config_keypad), GINT_TO_POINTER(i));


  g_signal_connect(GTK_OBJECT (myWidget_a->buttongrabarconfiguracion), "clicked", GTK_SIGNAL_FUNC (on_window_guardarconfiguracion), NULL);

}



void FormConfig::on_window_guardarconfiguracion(GtkWidget *widget_p,gpointer data_p) {
  errLog::LOGERR((errLog::TRACE,"Stub: on_window_guardarconfiguracion\n"));
  char bufferTxt[128];
  
  string dummy;

  config_g->serverHostName_a = gtk_entry_get_text (GTK_ENTRY(pFormConfig_a->myWidget_a->entryServerHostName));


  config_g->serverAddress_a  = gtk_entry_get_text (GTK_ENTRY(pFormConfig_a->myWidget_a->entryServerAddress));
  config_g->serverUrl_a      = gtk_entry_get_text (GTK_ENTRY(pFormConfig_a->myWidget_a->entryServerUrl));

  dummy                      = gtk_entry_get_text (GTK_ENTRY(pFormConfig_a->myWidget_a->entryServerPort));
  config_g->serverPort_a     = atoi(dummy.data());

  dummy                      = gtk_entry_get_text (GTK_ENTRY(pFormConfig_a->myWidget_a->entryServicioPort));
  config_g->portSocket_a     = atoi(dummy.data());

  config_g->addressSocket_a  = gtk_entry_get_text (GTK_ENTRY(pFormConfig_a->myWidget_a->entryServicioAddress));
  config_g->rfiddevice_a     = gtk_entry_get_text (GTK_ENTRY(pFormConfig_a->myWidget_a->entryServicioRfIdPort));

  config_g->wlanSSID_a       = gtk_entry_get_text (GTK_ENTRY(pFormConfig_a->myWidget_a->entryWlanSSID));
  config_g->wlanKey_a        = gtk_entry_get_text (GTK_ENTRY(pFormConfig_a->myWidget_a->entryWlanWpaKey));


  config_g->ethIpAddress_a   = gtk_entry_get_text (GTK_ENTRY(pFormConfig_a->myWidget_a->entryEthAddress));
  config_g->ethMask_a        = gtk_entry_get_text (GTK_ENTRY(pFormConfig_a->myWidget_a->entryEthMask));
  config_g->ethGateway_a     = gtk_entry_get_text (GTK_ENTRY(pFormConfig_a->myWidget_a->entryEthGateway));
  config_g->dns_a            = gtk_entry_get_text (GTK_ENTRY(pFormConfig_a->myWidget_a->entryDNS));

  if ( GTK_TOGGLE_BUTTON (pFormConfig_a->myWidget_a->checkbuttonEthDhcp)->active ) {
    config_g->ethDhcp_a = 1 ;
  } else {
    config_g->ethDhcp_a = 0 ;
  }


  GtkTreeIter   iter;
  GtkTreeModel  *model;
  char          *szDescripcion;
  char          *szId;
  
  model = gtk_combo_box_get_model(GTK_COMBO_BOX(pFormConfig_a->myWidget_a->comboboxProveedorMovil));

  if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX(pFormConfig_a->myWidget_a->comboboxProveedorMovil), &iter)) {
    gtk_tree_model_get(model, &iter, 0, &szId,  -1);
    gtk_tree_model_get(model, &iter, 1, &szDescripcion,  -1);
    errLog::LOGERR((errLog::TRACE, (char *)"Wvdial IdSelect %s %s\n",szId,szDescripcion));
    config_g->wvDial_a = szId;
    g_free(szId);
    g_free(szDescripcion);
  } 

  if (model) {
    g_object_unref (model);
  }

  if ( config_g->getParametro("port","server.socket",dummy) == 0 ) {
    sprintf(bufferTxt,"%d",config_g->portSocket_a);
    dummy = bufferTxt ;
    config_g->actualizaParametro("port","server.socket",dummy);
  } else {
    sprintf(bufferTxt,"%d",config_g->portSocket_a);
    dummy = bufferTxt ;
    config_g->ingresaParametro("port","server.socket",dummy);
  }



  if ( config_g->getParametro("address","server.socket",dummy) == 0 ) {
    config_g->actualizaParametro("address","server.socket",config_g->addressSocket_a);
  } else {
    config_g->ingresaParametro("address","server.socket",config_g->addressSocket_a);
  }


  if ( config_g->getParametro("hostname","server",dummy) == 0 ) {
    config_g->actualizaParametro("hostname","server",config_g->serverHostName_a);
  } else {
    config_g->ingresaParametro("hostname","server",config_g->serverHostName_a);
  }


  if ( config_g->getParametro("url","server",dummy) == 0 ) {
    config_g->actualizaParametro("url","server",config_g->serverUrl_a);
  } else {
    config_g->ingresaParametro("url","server",config_g->serverUrl_a);
  }


  if ( config_g->getParametro("address","server",dummy) == 0 ) {
    config_g->actualizaParametro("address","server",config_g->serverAddress_a);
  } else {
    config_g->ingresaParametro("address","server",config_g->serverAddress_a);
  }


  if ( config_g->getParametro("port","server",dummy) == 0 ) {
    sprintf(bufferTxt,"%d",config_g->serverPort_a);
    dummy = bufferTxt ;
    config_g->actualizaParametro("port","server",dummy);
  } else {
    sprintf(bufferTxt,"%d",config_g->serverPort_a);
    dummy = bufferTxt ;
    config_g->ingresaParametro("port","server",dummy);
  }

  if ( config_g->getParametro("device","rfid",dummy) == 0 ) {
    config_g->actualizaParametro("device","rfid",config_g->rfiddevice_a);
  } else {
    config_g->ingresaParametro("device","rfid",config_g->rfiddevice_a);
  }

  if ( config_g->getParametro("ipaddress","network.eth0",dummy) == 0 ) {
    config_g->actualizaParametro("ipaddress","network.eth0",config_g->ethIpAddress_a);
  } else {
    config_g->ingresaParametro("ipaddress","network.eth0",config_g->ethIpAddress_a);
  }

  if ( config_g->getParametro("gateway","network.eth0",dummy) == 0 ) {
    config_g->actualizaParametro("gateway","network.eth0",config_g->ethGateway_a);
  } else {
    config_g->ingresaParametro("gateway","network.eth0",config_g->ethGateway_a);
  }

  if ( config_g->getParametro("mask","network.eth0",dummy) == 0 ) {
    config_g->actualizaParametro("mask","network.eth0",config_g->ethMask_a);
  } else {
    config_g->ingresaParametro("mask","network.eth0",config_g->ethMask_a);
  }

  if ( config_g->getParametro("mask","network.eth0",dummy) == 0 ) {
    config_g->actualizaParametro("mask","network.eth0",config_g->ethMask_a);
  } else {
    config_g->ingresaParametro("mask","network.eth0",config_g->ethMask_a);
  }

  if ( config_g->getParametro("dhcp","network.eth0",dummy) == 0 ) {
    sprintf(bufferTxt,"%d",config_g->ethDhcp_a);
    dummy = bufferTxt ;
    config_g->actualizaParametro("dhcp","network.eth0",dummy);
  } else {
    sprintf(bufferTxt,"%d",config_g->ethDhcp_a);
    dummy = bufferTxt ;
    config_g->ingresaParametro("dhcp","network.eth0",dummy);
  }

  if ( config_g->getParametro("dns","network",dummy) == 0 ) {
    config_g->actualizaParametro("dns","network",config_g->dns_a);
  } else {
    config_g->ingresaParametro("dns","network",config_g->dns_a);
  }

  if ( config_g->getParametro("dns","network",dummy) == 0 ) {
    config_g->actualizaParametro("dns","network",config_g->dns_a);
  } else {
    config_g->ingresaParametro("dns","network",config_g->dns_a);
  }


//  if ( config_g->getParametro("dhcp","network.wlan",dummy) == 0 ) {
//    sprintf(bufferTxt,"%d",config_g->wlanDhcp_a);
//    dummy = bufferTxt ;
//    config_g->actualizaParametro("dhcp","network.wlan",dummy);
//  } else {
//    sprintf(bufferTxt,"%d",config_g->wlanDhcp_a);
//    dummy = bufferTxt ;
//    config_g->ingresaParametro("dhcp","network.wlan",dummy);
//  }

  if ( config_g->getParametro("ssid","network.wlan",dummy) == 0 ) {
    config_g->actualizaParametro("ssid","network.wlan",config_g->wlanSSID_a);
  } else {
    config_g->ingresaParametro("ssid","network.wlan",config_g->wlanSSID_a);
  }


  if ( config_g->getParametro("key","network.wlan",dummy) == 0 ) {
    config_g->actualizaParametro("key","network.wlan",config_g->wlanKey_a);
  } else {
    config_g->ingresaParametro("key","network.wlan",config_g->wlanKey_a);
  }

  if ( config_g->getParametro("wvdial","network.wvdial",dummy) == 0 ) {
    config_g->actualizaParametro("wvdial","network.wvdial",config_g->wvDial_a);
  } else {
    config_g->ingresaParametro("wvdial","network.wvdial",config_g->wvDial_a);
  }


}

void FormConfig::on_window_show(GtkWidget *widget_p,gpointer data_p) {

}

void FormConfig::on_window_destroy(GtkWidget *widget_p,gpointer data_p) {
  errLog::LOGERR((errLog::INFO, (char *)"Cierra FormConfig\n"));
  pFormConfig_a->flagInit_a = false ;
  gtk_widget_show(pFormConfig_a->windowParent_a);  
  global_g->windowActiva_a = MyGlobal::WINDOW_MAIN ;
}

void FormConfig::on_window_close(GtkWidget *widget_p,gpointer data_p) {
  gtk_widget_show(pFormConfig_a->windowParent_a); 
  gtk_widget_hide(pFormConfig_a->window_a);   
  global_g->windowActiva_a = MyGlobal::WINDOW_MAIN ;
  
}



void FormConfig::on_window_config_keypad(GtkWidget *widget_p,gpointer data_p) {
    char buffer[32];

    sprintf(buffer,"%c",GPOINTER_TO_INT (data_p));

    int dato=GPOINTER_TO_INT (data_p);

    errLog::LOGERR((errLog::TRACE,"on_window_config_keypad %s DATO=%X\n",buffer,dato));

    if ( dato == 0x20 ) {
      // Space Bar
      SendKey((char *)"space");		
    } else if ( dato == 0x08 ) {
      // Back Space
      SendKey((char *)"Back+");
    } else if ( dato == ',' ) {
      if ( pFormConfig_a->keyup_a%2 ) {
        SendKey((char *)"Shift+comma");
      } else {
        SendKey((char *)"comma");
      }
    } else if ( dato == '.' ) {
      if ( pFormConfig_a->keyup_a%2 ) {
        SendKey((char *)"Shift+colon");
      } else {
        SendKey((char *)"period");
      }
    } else if ( dato == '-' ) {
      if ( pFormConfig_a->keyup_a%2 ) {
        SendKey((char *)"Shift+minus");
      } else {
        SendKey((char *)"minus");
      }
    } else if ( dato == '/' ) {
      SendKey((char *)"Shift+slash");
    } else if ( dato==0x0E ) {
      int indexPos = 0 ;

      if ( pFormConfig_a->keyup_a++%2 ) {
        errLog::LOGERR((errLog::INFO,(char *)"Cambia Teclado abajo\n"));	

        indexPos = 0 ;
        for ( int index = '0' ; index <= '9' ; index++ ) {
          sprintf(buffer,"%c",index);
          gtk_button_set_label((GtkButton *)pFormConfig_a->myWidget_a->keypadnum[indexPos++],buffer);
        }

        indexPos=0;
        for ( int index = 'a' ; index <= 'z' ; index++ ) {
          sprintf(buffer,"%c",index);
          gtk_button_set_label((GtkButton *)pFormConfig_a->myWidget_a->keypadletter[indexPos++],buffer);
        }
        sprintf(buffer,"ñ");
        gtk_button_set_label((GtkButton *)pFormConfig_a->myWidget_a->keypadletter[indexPos++],buffer);

        sprintf(buffer,",");
        gtk_button_set_label((GtkButton *)pFormConfig_a->myWidget_a->keypadcomma,buffer);

        sprintf(buffer,".");
        gtk_button_set_label((GtkButton *)pFormConfig_a->myWidget_a->keypadpunto,buffer);

        sprintf(buffer,"-");
        gtk_button_set_label((GtkButton *)pFormConfig_a->myWidget_a->keypadraya,buffer);


      } else {
        errLog::LOGERR((errLog::INFO,(char *)"Cambia Teclado Arriba\n"));	
        indexPos=0;
        for ( int index = '0' ; index <= '9' ; index++ ) {
          char c;
          switch ( index ) {
            case '1':  c= '!' ; break;
            case '2':  c= '\"' ; break;
            case '3':  c= '@' ; break;
            case '4':  c= '$' ; break;
            case '5':  c= '%' ; break;
            case '6':  c= '&' ; break;
            case '7':  c= '#' ; break;  // keysym 0x37 shift 1
            case '8':  c= '(' ; break;
            case '9':  c= ')' ; break;
            case '0':  c= '=' ; break; // keysym 0x30 shift 1
            default: c='L';break;
          } ;

          sprintf(buffer,"%c",c);
          gtk_button_set_label((GtkButton *)pFormConfig_a->myWidget_a->keypadnum[indexPos++],buffer);
        }
        
        indexPos=0;
        for ( int index = 'A' ; index <= 'Z' ; index++ ) {
          sprintf(buffer,"%c",index);
          gtk_button_set_label((GtkButton *)pFormConfig_a->myWidget_a->keypadletter[indexPos++],buffer);
        }
        sprintf(buffer,"Ñ");
        gtk_button_set_label((GtkButton *)pFormConfig_a->myWidget_a->keypadletter[indexPos++],buffer);

        sprintf(buffer,";");
        gtk_button_set_label((GtkButton *)pFormConfig_a->myWidget_a->keypadcomma,buffer);

        sprintf(buffer,":");
        gtk_button_set_label((GtkButton *)pFormConfig_a->myWidget_a->keypadpunto,buffer);

        sprintf(buffer,"_");
        gtk_button_set_label((GtkButton *)pFormConfig_a->myWidget_a->keypadraya,buffer);
        
      }
      
      ///////////////
    } else {
        //~ 
      string mystr=buffer;


      int keysym ;
      if ( pFormConfig_a->keyup_a%2 ) {
        switch ( dato ) {
          case '1': keysym=0x31;break;
          case '2': keysym=0x32;break;
          case '3': keysym=0x40;break;
          case '4': keysym=0x34;break;
          case '5': keysym=0x35;break;
          case '6': keysym=0x36;break;
          case '7': keysym=0x23;break;
          case '8': keysym=0x38;break;
          case '9': keysym=0x39;break;
          case '0': keysym=0x30;break;
          default: keysym=-1;break;
        } ;
        if ( keysym != -1 ) {
          SendKeySym(keysym,1);
        } else {
          mystr = "Shift+" + mystr ;
          SendKey((char *)mystr.data());
        }
      } else {
        SendKey((char *)mystr.data());
      }
        


    }

}


void FormConfig::initComboboxPPP() {
  GtkTreeIter		iter      ;
  GtkListStore		*store    ;
 
  store     = gtk_list_store_new(2, G_TYPE_STRING,G_TYPE_STRING);
  gtk_combo_box_set_model(GTK_COMBO_BOX(myWidget_a->comboboxProveedorMovil), GTK_TREE_MODEL(store));

  GtkCellRenderer 	*cell ;
  cell  = gtk_cell_renderer_text_new();

  gtk_list_store_append(store, &iter);
  gtk_list_store_set(store, &iter, 0, "ENTEL",1, "ENTEL",-1);
  gtk_list_store_append(store, &iter);
  gtk_list_store_set(store, &iter, 0, "CLARO", 1, "CLARO",-1);
  gtk_list_store_append(store, &iter);
  gtk_list_store_set(store, &iter, 0, "MOVISTAR",1, "MOVISTAR",-1);
  gtk_list_store_append(store, &iter);
  
  gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(myWidget_a->comboboxProveedorMovil),cell,TRUE);
  gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(myWidget_a->comboboxProveedorMovil),cell,"text",1,NULL);
	gtk_combo_box_set_active(GTK_COMBO_BOX(myWidget_a->comboboxProveedorMovil),-1);

  g_object_unref(store);
}

